<template>
  <div class="app-container">

    <el-table v-loading="loading" :data="resultAllList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" align="center" />
      <el-table-column label="专利编号" align="center" prop="proId" width="100" sortable />
      <el-table-column label="专利名称" align="center" prop="proName" />
      <el-table-column label="所属小组" align="center" prop="groupName" width="200" />
      <el-table-column label="专利描述" align="center" prop="userName" />
      <el-table-column label="专利作者" align="center" prop="proAuthor" />
      <el-table-column label="评审时间" align="center" prop="updateTime" width="200PX" :formatter="dateFormat" />
      <el-table-column label="评审分数" align="center" prop="score" sortable width="100PX">
        <div slot-scope="scope">
          <el-tag type="success" v-if="scope.row.score>=80">{{scope.row.score}}</el-tag>
          <el-tag type="warning" v-else-if="scope.row.score>=60&&scope.row.score<80">{{scope.row.score}}</el-tag>
          <el-tag type="danger" v-else-if="scope.row.score>0&&scope.row.score<60">{{scope.row.score}}</el-tag>
          <el-tag type="info" v-else-if="scope.row.score==null||scope.row.score=='' ">未评分</el-tag>
        </div>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['project:projectData:remove']" disabled>删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getAllScore" />

  </div>
</template>

<script>
import { getProjectData, delProjectData, updateProjectData } from "@/api/system/project/projectData";
import { selectAllScore } from "@/api/system/project/project";
import moment from "moment";
export default {
  name: "ProjectData",
  data () {
    return {
      activeName: 'second',
      // 遮罩层
      loading: true,
      statusText: "",
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 专利数据表格数据
      projectDataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      rowid: '',
      progress1: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        proName: null,
        proFile: null,
        proType: null,
        proDescr: null,
        proAuthor: null,
        proCreatetime: null,
        proGroupStatus: null,
        groupId: null,
        status: null
      },
      // 表单参数
      form: {},
      resultAllList: [],
      // 表单校验
      rules: {
      },
      examineList: [],
      adoptList: [],
      reject: []
    };
  },
  created () {
    this.getAllScore()
  },
  computed: {

    progress () {
      return this.$store.state.myProject.progress
    }
  },
  watch: {
    progress (newval, oldval) {
      this.progress1 = newval
    }
  },
  methods: {
    //时间格式化
    dateFormat: function (row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return moment(date).format("YYYY-MM-DD HH:mm");
    },
    getAllScore () {
      selectAllScore(this.queryParams).then(res => {
        this.loading = false,
          this.resultAllList = res.rows
        this.total = res.total
        console.log(this.resultAllList)
      })
    },

    /** 查询专利数据列表 */

    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        id: null,
        proName: null,
        proFile: null,
        proType: null,
        proDescr: null,
        proAuthor: null,
        proCreatetime: null,
        proGroupStatus: 0,
        groupId: null,
        userId: null,
        status: 0
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd () {
      this.reset();
      this.open = true;
      this.title = "添加专利数据";
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.reset();
      const id = row.id || this.ids
      getProjectData(id).then(response => {
        this.form = response.data;
        this.form.status = 1
        updateProjectData(this.form).then(response => {
          this.$modal.msgSuccess("审核通过");
          this.getList();
        });
      });
    },
    handleReject (row) {
      this.reset();
      const id = row.id || this.ids
      getProjectData(id).then(response => {
        this.form = response.data;
        this.form.status = 2
        updateProjectData(this.form).then(response => {
          this.$modal.msgSuccess("已驳回专利");
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete (row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除专利数据编号为"' + ids + '"的数据项？').then(function () {
        return delProjectData(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport () {
      this.download('project/projectData/export', {
        ...this.queryParams
      }, `projectData_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
